// bosstwin.txt

// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//   Cell 3 - Who is this char's twin?
// 4,5 - two pts
begincreaturescript;

variables;

short i,target;
short path_a_or_b = 0;
short last_walk;
short last_abil;
short fire_level = 20;

body;

beginstate INIT_STATE;
	set_name(ME,"Twin Defender");
	set_level(ME,30);
	change_max_health(ME,800);
	set_boss_level(ME,2);
	set_aggression(ME,9);

	last_abil = get_current_tick();
	last_walk = get_current_tick();
	
	sf(71,14,0);
	break;

beginstate DEAD_STATE;
	last_walk = get_current_tick();

break;

beginstate START_STATE; 
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
		
	if ((get_attitude(ME) >= 10) && (dist_to_pc() <= 50) && (gf(71,14) > 0)) {
		set_foe_target(ME,pc_num());
		set_state(3);
		}

if (path_a_or_b == 0) {
		if (tick_difference(last_walk,get_current_tick()) > 3) {
			approach_nav_point(ME,get_memory_cell(4),1);
			if (dist_to_nav_point(ME,get_memory_cell(4)) <= 2) {
				last_walk = get_current_tick();
				path_a_or_b = 1;
				}
	
			}	
		}
	else if (path_a_or_b == 2) {
		if (tick_difference(last_walk,get_current_tick()) > 3) {
			approach_nav_point(ME,get_memory_cell(5),1);
			if (dist_to_nav_point(ME,get_memory_cell(5)) <= 2) {
				last_walk = get_current_tick();
				path_a_or_b = 3;
				}
	
			}	
		}
		else if (path_a_or_b == 1) {
			if (tick_difference(last_walk,get_current_tick()) > 3) {
				if (return_to_start(ME,2)) {
					last_walk = get_current_tick();
					path_a_or_b = 2;		
					}
				}
			}
		else if (path_a_or_b == 3) {
			if (tick_difference(last_walk,get_current_tick()) > 3) {
				if (return_to_start(ME,2)) {
					last_walk = get_current_tick();
					path_a_or_b = 0;		
					}
				}
			}

	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	sf(71,14,1);
	
	if ((char_ok(get_memory_cell(3))) && (dist_to_char(get_memory_cell(3)) < 15)) {
		if ((tick_difference(last_abil,get_current_tick()) > 0) && (get_health(ME) < (get_health(get_memory_cell(3)) * 9) / 10)) {
			print_named_str(ME,"draws energy from its twin and sprays it into the air.");
			run_char_animation(2,1,35);	
			last_abil = get_current_tick();

		  	place_particle_num(ME,1,4,8);
			pc_heard_sound_delay(179,250);						
	  		create_missile_spiral(155,40,8,2);
	  		damage_nearby(get_ran(fire_level,1,10),8,1,0);
	  		if (fire_level >= 40)
	  			status_nearby(3,8,20,0);
	  		fire_level = fire_level + 10;
	  		

	  		if (gf(71,15) == 0) {
	  			sf(71,15,1);
	  			begin_talk_mode(10);
	  			}
	  		end();
	  		}
		}
		
	if (target_ok() == FALSE)
		set_state(START_STATE);
	do_attack();
break;

beginstate TALKING_STATE;
	print_str("Talking: It doesn't respond.");
break;